#!/bin/bash

randomNum() {
	if [ $# -eq 1 ];then
		(( rand = $RANDOM*$1/32767 ))
		echo $rand
	else
		echo $RANDOM
	fi
}

completar() {
	formedNumber=""
	if [ $# -eq 2 ];then
		(( max = $2 - 1 ))

		for (( i = $max; i >= 0; i-- ))
		do
			((tenth = 10 ** $i))
			if [ $1 -lt $tenth ];then
				formedNumber=$formedNumber"0"
			else
				formedNumber=$formedNumber"$1"
				break;
			fi
		done
		echo $formedNumber
	else
		echo "maaaaaaaal"
	fi
}

genRegistro() {

	codCliente=CLIENTE
	grMorosidad=
	deuda=

	
	var=`completar $1 3`
	codCliente=$codCliente$var


	var=`randomNum 6`
	grMorosidad=`completar $var 2`

	#arbitrario:
	#gr 0 --> deuda 0
	#gr 1 --> deuda 0-500
	#gr 2 --> deuda 500-2000
	#gr 3 --> deuda 2000-5000
	#gr 4 --> deuda 5000-10000
	#gr 5 --> deuda >10000
	case $grMorosidad in
		00)	deuda=`completar 0 10`;;
		01)	var=`randomNum 500`
			deuda=`completar $var 10`;;
		02) var=`randomNum 1500`
			(( var = $var + 500 ))
			deuda=`completar $var 10`;;
		03) var=`randomNum 3000`
			(( var = $var + 2000 ))
			deuda=`completar $var 10`;;
		04) var=`randomNum 5000`
			(( var = $var + 5000 ))
			deuda=`completar $var 10`;;
		05) var=`randomNum 100000`
			(( var = $var + 10000 ))
			deuda=`completar $var 10`;;
	esac
	
	registro=$codCliente","$grMorosidad","$deuda

	echo $registro
}


for (( i = 1 ; i < 1000 ; i++ ))
do
	registro=`genRegistro $i`
	echo $registro
done

